#load libraries
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.2.1 ✔ purrr 0.3.2
## ✔ tibble 2.1.3 ✔ dplyr 0.8.3
## ✔ tidyr 1.0.0 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(shiny)
library(leaflet)
library(tigris)
## To enable
## caching of data, set `options(tigris_use_cache = TRUE)` in your R script or .Rprofile.
##
## Attaching package: 'tigris'
## The following object is masked from 'package:graphics':
##
## plot
library(htmlwidgets)
load("pd.Rdata")
I wanted to create an interactive graphic that shows the distribution of income by median household value. The interactive graphic allows the user to see the various counties scattered throughout the plot.
Independent variable: median household value - ‘median_home_val’ Dependent variable: income - ‘per_capita_inc’
gg<-ggplot(pd,
aes(x=median_home_val,y=per_capita_inc,
text=paste0(county,
"<br>",
"Percent College Grad: ",
round(coll_grad_pc,1),
"<br>",
"Median Home Value: ",
round(median_home_val,1)) ))
gg<-gg+geom_point(color="blue")
gg<-gg+xlab("Median Household Value")+ylab("Income")
gg<-ggplotly(gg)
gg
saveWidget(widget=gg,file="assignment13_chen_widget.html")